<template>
    <view>
        <cu-custom bgColor="bg-gradual-pink" :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">登录</block>
        </cu-custom>
        <form>
            <view class="cu-form-group margin-top">
                <view class="title">手机号</view>
                <input v-model="form.account" placeholder="请输入手机号" name="input"></input>
            </view>
            <view class="cu-form-group">
                <view class="title">验证码</view>
                <input v-model="form.code" placeholder="请输入验证码" name="input"></input>
                <button @click="sendCode" class='cu-btn bg-green shadow'>获取验证码</button>
            </view>
            <view class="padding flex flex-wrap justify-between align-center bg-white">
                <button @click="login" style="color: white;background: limegreen;">登录</button>
            </view>
            <view style="color: blue;" class="padding flex flex-wrap justify-end align-end bg-white">
                <a href="http://localhost:8080/#/pages/signIn/passenger" class="link">没有账号?去注册</a>
            </view>
        </form>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                form:{
                    account:"",
                    code:""
                }
            }
        },
        methods: {
            sendCode(){
                uni.request({
                    url:"http://localhost:10010/user/getCode/"+this.form.account,
                    method:'GET',
                    success:function(res){
                        if(res.data.code==200){
                            uni.showToast({
                                title: "验证码发送成功",
                            })
                        }
                    }
                })
            },
			login(){
				uni.request({
				    url:"http://localhost:10010/user/loginByCode",
					data:this.form,
				    method:'POST',
				    success:function(res){
				        if(res.data.code==200){
				          uni.showToast({
				              title: "登录成功",
				          });
						  localStorage.setItem("user",JSON.stringify(res.data.data));
						  localStorage.setItem("token",res.data.data.token);
				        }
						/* 跳转页面 */
						uni.navigateTo({
							//路径
							url: '/pages/index/index'
						});
				    }
				})
			}
        }
    }
</script>

<style>

</style>